package cn.whb.hrm.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {
    public static final String COURSE_ONLINE_NOTICE_EXCHANGE="course_online_notice_exchange";
    public static final String COURSE_ONLINE_NOTICE_QUEUE_SMS="course_online_notice_queue_sms";
    public static final String COURSE_ONLINE_NOTICE_QUEUE_EMALI="course_online_notice_queue_emali";
    public static final String COURSE_ONLINE_NOTICE_QUEUE_SYSTEM="course_online_notice_queue_system";
    //创建交换机
    @Bean
    public Exchange creatExchange(){
        return ExchangeBuilder.topicExchange(COURSE_ONLINE_NOTICE_EXCHANGE).durable(true).build();
    }

    //创建队列
    @Bean
    public Queue smsQueue(){
        return new Queue(COURSE_ONLINE_NOTICE_QUEUE_SMS,true);
    }
    //创建队列
    @Bean
    public Queue emailQueue(){
        return new Queue(COURSE_ONLINE_NOTICE_QUEUE_EMALI,true);
    }
    //创建队列
    @Bean
    public Queue systemQueue(){
        return new Queue(COURSE_ONLINE_NOTICE_QUEUE_SYSTEM,true);
    }

    //绑定队列和交换机
    @Bean
    public Binding smsQueueBinding(){
        return BindingBuilder.bind(smsQueue()).to(creatExchange()).with("message.sms").noargs();
    }

    //绑定队列和交换机
    @Bean
    public Binding emailQueueBinding(){
        return BindingBuilder.bind(emailQueue()).to(creatExchange()).with("message.email").noargs();
    }

    //绑定队列和交换机
    @Bean
    public Binding systemQueueBinding(){
        return BindingBuilder.bind(systemQueue()).to(creatExchange()).with("message.system").noargs();
    }
}
